package com.shurdroides.proyectofinal.preferences;

import com.google.android.maps.GeoPoint;
import com.shurdroides.proyectofinal.constants.Constants;

import android.content.Context;
import android.content.SharedPreferences;
import android.location.Location;

public class MyPreferences implements Constants {

	private SharedPreferences sharedPreferences;
	private SharedPreferences.Editor editor;
	private Context ctx;
	private int userId;
	private boolean first;

	/**
	 * 
	 * @param ctx
	 */
	public MyPreferences(Context ctx) {
		super();
		this.ctx = ctx;
		sharedPreferences = ctx.getSharedPreferences(Preferences.PREFS_NAME,
				Context.MODE_PRIVATE);
		editor = sharedPreferences.edit();
	}

	

	public void setFirst(boolean b) {
		editor.putBoolean(Preferences.FIRST_TIME, b);
		editor.commit();
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public boolean getFirst() {
		return sharedPreferences.getBoolean(Preferences.FIRST_TIME,
				true);
	}
	
	public String getAuthenticationToken() {
		return sharedPreferences.getString(Preferences.AUTHENTICATION_TOKEN,
				Preferences.DEFAULT_AUTHENTICATION_TOKEN);
	}
	
	public void updateAuthenticationToken(String authToken) {
		editor.putString(Preferences.AUTHENTICATION_TOKEN, authToken);
		editor.commit();
	}
	
	public String getName() {
		return sharedPreferences.getString(Preferences.NOMBRE_USUARIO,
				"user");
	}
	
	public void updateName(String name) {
		editor.putString(Preferences.NOMBRE_USUARIO, name);
		editor.commit();
	}
	

	public String getAccount() {
		return sharedPreferences.getString(Preferences.ACCOUNT, null);
	}

	public void updateAccount(String s) {
		editor.putString(Preferences.ACCOUNT, s);
		editor.commit();
	}

	public boolean getDentro() {
		return sharedPreferences.getBoolean(Preferences.DENTRO, false);
	}

	public void updateDentro(boolean s) {
		editor.putBoolean(Preferences.DENTRO, s);
		editor.commit();
	}
	
	public String getDeviceRegistration() {
		return sharedPreferences.getString(Preferences.DEVICE_REGISTRATION,
				null);
	}

	public void updateDeviceRegistration(String s) {
		editor.putString(Preferences.DEVICE_REGISTRATION, s);
		editor.commit();
	}

	public void removeDeviceRegistration() {
		editor.remove(Preferences.DEVICE_REGISTRATION);
		editor.commit();
	}

	public void updateRanking(String ranking) {
		editor.putString(Preferences.RANKING, ranking);
		editor.commit();
	}

	public String getRanking() {
		return sharedPreferences.getString(Preferences.RANKING, "");
	}

	public void updateCueva(GeoPoint g) {
		editor.putInt(Preferences.CUEVA_LAT, g.getLatitudeE6());
		editor.putInt(Preferences.CUEVA_LON, g.getLongitudeE6());
		editor.commit();
	}
	
	public void updateCueva(int lat, int lon) {
		editor.putInt(Preferences.CUEVA_LAT, lat);
		editor.putInt(Preferences.CUEVA_LON, lon);
		editor.commit();
	}

	public GeoPoint getCueva() {
		return new GeoPoint(sharedPreferences.getInt(Preferences.CUEVA_LAT, 0),
				sharedPreferences.getInt(Preferences.CUEVA_LAT, 0));
	}

}